// FES = From External Source
package userfes

import (
	// internal - domain - main-entities
	ecore "simrs-vx/internal/domain/base-entities/core"
	eap "simrs-vx/internal/domain/main-entities/auth-partner"
)

type CreateDto struct {
	Name             string `json:"name"`
	AuthPartner_Code string `json:"authPartner_code"`
	User_Name        string `json:"user_name"`
}

type ReadListDto struct {
	FilterDto
	Includes   string `json:"includes"`
	Pagination ecore.Pagination
	Sort       string `json:"sort"`
}

type FilterDto struct {
	Name             *string `json:"name"`
	AuthPartner_Code *string `json:"authPartner_code"`
	User_Name        *string `json:"user_name"`
	Includes         string  `json:"includes"`
}

type ReadDetailDto struct {
	Id       uint   `json:"id"`
	Includes string `json:"includes"`
}

type UpdateDto struct {
	Id uint `json:"id"`
	CreateDto
}

type DeleteDto struct {
	Id uint `json:"id"`
}

type LoginDto struct {
	Name                  string `json:"name" validate:"required"`
	Duration              uint32 `json:"duration"`
	AuthPartner_Code      string `json:"X-AuthPartner-Code" validate:"required"`
	AuthPartner_SecretKey string `json:"X-AuthPartner-SecretKey" validate:"required"`
}

type MetaDto struct {
	PageNumber int `json:"page_number"`
	PageSize   int `json:"page_size"`
	Count      int `json:"count"`
}

type ResponseDto struct {
	ecore.Main
	Name             string           `json:"name"`
	AuthPartner_Code string           `json:"authPartner_code"`
	AuthPartner      *eap.AuthPartner `json:"authPartner,omitempty"`
	User_Name        string           `json:"user_name"`
}

func (d UserFes) ToResponse() ResponseDto {
	resp := ResponseDto{
		Name:             d.Name,
		AuthPartner_Code: d.AuthPartner_Code,
		// AuthPartner:      d.AuthPartner,
		User_Name: d.User_Name,
	}
	resp.Main = d.Main
	return resp
}

func ToResponseList(data []UserFes) []ResponseDto {
	resp := make([]ResponseDto, len(data))
	for i, u := range data {
		resp[i] = u.ToResponse()
	}
	return resp
}
