package entities

import (
	"time"

	"github.com/google/uuid"
)

type LetterIncomingDisposition struct {
	ID               uuid.UUID                             `gorm:"type:uuid;primary_key;default:gen_random_uuid()" json:"id"`
	LetterID         uuid.UUID                             `gorm:"type:uuid;not null" json:"letter_id"`
	DepartmentID     *uuid.UUID                            `json:"department_id,omitempty"`
	Notes            *string                               `json:"notes,omitempty"`
	ReadAt           *time.Time                            `json:"read_at,omitempty"`
	CreatedAt        time.Time                             `gorm:"autoCreateTime" json:"created_at"`
	CreatedBy        uuid.UUID                             `gorm:"not null" json:"created_by"`
	UpdatedAt        time.Time                             `gorm:"autoUpdateTime" json:"updated_at"`
	Department       Department                            `gorm:"foreignKey:DepartmentID;references:ID" json:"department,omitempty"`
	Departments      []LetterIncomingDispositionDepartment `gorm:"foreignKey:LetterIncomingDispositionID;references:ID" json:"departments,omitempty"`
	ActionSelections []LetterDispositionActionSelection    `gorm:"foreignKey:DispositionID;references:ID" json:"action_selections,omitempty"`
	DispositionNotes []DispositionNote                     `gorm:"foreignKey:DispositionID;references:ID" json:"disposition_notes,omitempty"`
}

func (LetterIncomingDisposition) TableName() string { return "letter_incoming_dispositions" }

type LetterIncomingDispositionDepartment struct {
	ID                          uuid.UUID `gorm:"type:uuid;primary_key;default:gen_random_uuid()" json:"id"`
	LetterIncomingDispositionID uuid.UUID `gorm:"type:uuid;not null" json:"letter_incoming_disposition_id"`
	DepartmentID                uuid.UUID `gorm:"type:uuid;not null" json:"department_id"`
	CreatedAt                   time.Time `gorm:"autoCreateTime" json:"created_at"`

	// Relationships
	Department *Department `gorm:"foreignKey:DepartmentID;references:ID" json:"department,omitempty"`
}

func (LetterIncomingDispositionDepartment) TableName() string {
	return "letter_incoming_dispositions_department"
}

type DispositionNote struct {
	ID            uuid.UUID  `gorm:"type:uuid;primary_key;default:gen_random_uuid()" json:"id"`
	DispositionID uuid.UUID  `gorm:"type:uuid;not null" json:"disposition_id"`
	UserID        *uuid.UUID `json:"user_id,omitempty"`
	Note          string     `gorm:"not null" json:"note"`
	CreatedAt     time.Time  `gorm:"autoCreateTime" json:"created_at"`

	// Relationships
	User *User `gorm:"foreignKey:UserID;references:ID" json:"user,omitempty"`
}

func (DispositionNote) TableName() string { return "disposition_notes" }

type LetterDispositionActionSelection struct {
	ID            uuid.UUID `gorm:"type:uuid;primary_key;default:gen_random_uuid()" json:"id"`
	DispositionID uuid.UUID `gorm:"type:uuid;not null" json:"disposition_id"`
	ActionID      uuid.UUID `gorm:"type:uuid;not null" json:"action_id"`
	Note          *string   `json:"note,omitempty"`
	CreatedBy     uuid.UUID `gorm:"not null" json:"created_by"`
	CreatedAt     time.Time `gorm:"autoCreateTime" json:"created_at"`

	// Relationships
	Action *DispositionAction `gorm:"foreignKey:ActionID;references:ID" json:"action,omitempty"`
}

func (LetterDispositionActionSelection) TableName() string { return "letter_disposition_actions" }
