package personcontact

import (
	ecore "simrs-vx/internal/domain/base-entities/core"
	erp "simrs-vx/internal/domain/references/person"
)

type CreateDto struct {
	Person_Id uint                `json:"person_id"`
	Type_Code erp.ContactTypeCode `json:"type_code" validate:"maxLength=15"`
	Value     string              `json:"value" validate:"maxLength=100"`
}

type ReadListDto struct {
	Pagination ecore.Pagination
}

type ReadDetailDto struct {
	Id        uint `json:"id"`
	Person_Id uint `json:"person_id"`
}

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

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

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

type ResponseDto struct {
	ecore.Main
	Person_Id uint                `json:"person_id"`
	Type_Code erp.ContactTypeCode `json:"type_code"`
	Value     string              `json:"value"`
}

func (d *PersonContact) ToResponse() ResponseDto {
	resp := ResponseDto{
		Person_Id: d.Person_Id,
		Type_Code: d.Type_Code,
		Value:     d.Value,
	}
	resp.Main = d.Main
	return resp
}

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