package entities

import (
	"time"

	"github.com/google/uuid"
)

type LetterIncomingStatus string

const (
	LetterIncomingStatusNew        LetterIncomingStatus = "new"
	LetterIncomingStatusInProgress LetterIncomingStatus = "in_progress"
	LetterIncomingStatusCompleted  LetterIncomingStatus = "completed"
)

type LetterIncoming struct {
	ID                  uuid.UUID            `gorm:"type:uuid;primary_key;default:gen_random_uuid()" json:"id"`
	LetterNumber        string               `gorm:"uniqueIndex;not null" json:"letter_number"`
	ReferenceNumber     *string              `json:"reference_number,omitempty"`
	Subject             string               `gorm:"not null" json:"subject"`
	Description         *string              `json:"description,omitempty"`
	PriorityID          *uuid.UUID           `json:"priority_id,omitempty"`
	SenderInstitutionID *uuid.UUID           `json:"sender_institution_id,omitempty"`
	ReceivedDate        time.Time            `json:"received_date"`
	DueDate             *time.Time           `json:"due_date,omitempty"`
	Status              LetterIncomingStatus `gorm:"not null;default:'new'" json:"status"`
	CreatedBy           uuid.UUID            `gorm:"not null" json:"created_by"`
	CreatedAt           time.Time            `gorm:"autoCreateTime" json:"created_at"`
	UpdatedAt           time.Time            `gorm:"autoUpdateTime" json:"updated_at"`
}

func (LetterIncoming) TableName() string { return "letters_incoming" }

type LetterIncomingAttachment 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"`
	FileURL    string     `gorm:"not null" json:"file_url"`
	FileName   string     `gorm:"not null" json:"file_name"`
	FileType   string     `gorm:"not null" json:"file_type"`
	UploadedBy *uuid.UUID `json:"uploaded_by,omitempty"`
	UploadedAt time.Time  `gorm:"autoCreateTime" json:"uploaded_at"`
}

func (LetterIncomingAttachment) TableName() string { return "letter_incoming_attachments" }
