package controlletter

import (
	// std
	"time"

	// internal - lib

	// internal - domain - base-entities
	ecore "simrs-vx/internal/domain/base-entities/core"

	// internal - domain - main-entities

	ed "simrs-vx/internal/domain/main-entities/doctor"
	ee "simrs-vx/internal/domain/main-entities/encounter"
	es "simrs-vx/internal/domain/main-entities/specialist"
	ess "simrs-vx/internal/domain/main-entities/subspecialist"
	eu "simrs-vx/internal/domain/main-entities/unit"
)

type CreateDto struct {
	Encounter_Id       *uint      `json:"encounter_id"`
	Unit_Code          *string    `json:"unit_code"`
	Specialist_Code    *string    `json:"specialist_code"`
	Subspecialist_Code *string    `json:"subspecialist_code"`
	Doctor_Code        *string    `json:"doctor_code"`
	Date               *time.Time `json:"date"`
}

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

type FilterDto struct {
	Encounter_Id       *uint      `json:"encounter-id"`
	Unit_Code          *string    `json:"unit-code"`
	Specialist_Code    *string    `json:"specialist-code"`
	Subspecialist_Code *string    `json:"subspecialist-code"`
	Doctor_Code        *string    `json:"doctor-code"`
	Date               *time.Time `json:"date"`
}

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

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
	Encounter_Id       *uint              `json:"encounter_id"`
	Encounter          *ee.Encounter      `json:"encounter,omitempty"`
	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"`
	Doctor_Code        *string            `json:"doctor_code"`
	Doctor             *ed.Doctor         `json:"doctor,omitempty"`
	Date               *time.Time         `json:"date"`
}

func (d ControlLetter) ToResponse() ResponseDto {
	resp := ResponseDto{
		Encounter_Id:       d.Encounter_Id,
		Encounter:          d.Encounter,
		Unit_Code:          d.Unit_Code,
		Unit:               d.Unit,
		Specialist_Code:    d.Specialist_Code,
		Specialist:         d.Specialist,
		Subspecialist_Code: d.Subspecialist_Code,
		Subspecialist:      d.Subspecialist,
		Doctor_Code:        d.Doctor_Code,
		Doctor:             d.Doctor,
		Date:               d.Date,
	}
	resp.Main = d.Main
	return resp
}

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