package doctor

import (
	ecore "simrs-vx/internal/domain/base-entities/core"
	ee "simrs-vx/internal/domain/main-entities/employee"
	es "simrs-vx/internal/domain/main-entities/specialist"
	ess "simrs-vx/internal/domain/main-entities/subspecialist"
	eu "simrs-vx/internal/domain/main-entities/unit"
	"time"
)

type CreateDto struct {
	Code               *string    `json:"code" validate:"maxLength=20"`
	Employee_Id        *uint      `json:"employee_id"`
	IHS_Number         *string    `json:"ihs_number"`
	SIP_Number         *string    `json:"sip_number"`
	SIP_ExpiredDate    *time.Time `json:"sip_expiredDate"`
	Unit_Code          *string    `json:"unit_code"`
	Specialist_Code    *string    `json:"specialist_code"`
	Subspecialist_Code *string    `json:"subspecialist_code"`
}

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

type FilterDto struct {
	Code               *string `json:"code"`
	Employee_Id        *uint   `json:"employee-id"`
	IHS_Number         *string `json:"ihs-number" validate:"maxLength=20"`
	SIP_Number         *string `json:"sip-number" validate:"maxLength=20"`
	SIP_ExpiredDate    *string `json:"sip-expiredDate"`
	Unit_Code          *string `json:"unit-code"`
	Specialist_Code    *string `json:"specialist-code"`
	Subspecialist_Code *string `json:"subspecialist-code"`
}

type ReadDetailDto struct {
	Id          *uint16 `json:"id"`
	Code        *string `json:"code"`
	Employee_Id *uint   `json:"employee_id"`
	IHS_Number  *string `json:"ihs_number"`
	SIP_Number  *string `json:"sip_number"`
	Includes    string  `json:"includes"`
}

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

type DeleteDto struct {
	Id   uint    `json:"id"`
	Code *string `json:"code"`
}

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

type ResponseDto struct {
	ecore.Main
	Code               *string            `json:"code"`
	Employee_Id        *uint              `json:"employee_id"`
	Employee           *ee.Employee       `json:"employee,omitempty"`
	IHS_Number         *string            `json:"ihs_number"`
	SIP_Number         *string            `json:"sip_number"`
	Unit_Code          *string            `json:"unit_code"`
	Unit               *eu.Unit           `json:"unit,omitempty"`
	Specialist_Code    *string            `json:"specialist_code"`
	Specialist         *es.Specialist     `json:"specialist,omitempty" `
	Subspecialist_Code *string            `json:"subspecialist_code"`
	Subspecialist      *ess.Subspecialist `json:"subspecialist,omitempty"`
}

func (d Doctor) ToResponse() ResponseDto {
	resp := ResponseDto{
		Code:               d.Code,
		Employee_Id:        d.Employee_Id,
		Employee:           d.Employee,
		IHS_Number:         d.IHS_Number,
		SIP_Number:         d.SIP_Number,
		Unit_Code:          d.Unit_Code,
		Unit:               d.Unit,
		Specialist_Code:    d.Specialist_Code,
		Specialist:         d.Specialist,
		Subspecialist_Code: d.Subspecialist_Code,
		Subspecialist:      d.Subspecialist,
	}
	resp.Main = d.Main
	return resp
}

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