package personinsurance

import (
	ecore "simrs-vx/internal/domain/base-entities/core"
	ei "simrs-vx/internal/domain/main-entities/insurance-company"
)

type CreateDto struct {
	Person_Id           uint    `json:"person_id"`
	InsuranceCompany_Id *uint   `json:"insurance_id"`
	Ref_Number          *string `json:"ref_number" gorm:"unique;size:20"`
	DefaultStatus       *bool   `json:"default_status" gorm:"uniqueIndex:idx_person_insurance"`
}

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

type FilterDto struct {
	Person_Id           *uint   `json:"person-id"`
	InsuranceCompany_Id *uint   `json:"insurance-company-id"`
	Ref_Number          *string `json:"ref-number"`
	DefaultStatus       *bool   `json:"default-status"`
}

type ReadDetailDto struct {
	Id uint16 `json:"id"`
}

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

type DeleteDto struct {
	Id uint16 `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"`
	InsuranceCompany_Id *uint                `json:"insuranceCompany_id"`
	InsuranceCompany    *ei.InsuranceCompany `json:"insuranceCompany,omitempty"`
	Ref_Number          *string              `json:"ref_number"`
	DefaultStatus       *bool                `json:"defaultStatus"`
}

func (d PersonInsurance) ToResponse() ResponseDto {
	resp := ResponseDto{
		Person_Id:           d.Person_Id,
		InsuranceCompany_Id: d.InsuranceCompany_Id,
		InsuranceCompany:    d.InsuranceCompany,
		Ref_Number:          d.Ref_Number,
		DefaultStatus:       d.DefaultStatus,
	}
	resp.Main = d.Main
	return resp
}

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