package contract

import (
	"time"

	"github.com/google/uuid"
)

type DepartmentInfo struct {
	ID   uuid.UUID `json:"id"`
	Name string    `json:"name"`
	Code string    `json:"code,omitempty"`
}

type DispositionRouteResponse struct {
	ID               uuid.UUID              `json:"id"`
	FromDepartmentID uuid.UUID              `json:"from_department_id"`
	ToDepartmentID   uuid.UUID              `json:"to_department_id"`
	IsActive         bool                   `json:"is_active"`
	AllowedActions   map[string]interface{} `json:"allowed_actions,omitempty"`
	CreatedAt        time.Time              `json:"created_at"`
	UpdatedAt        time.Time              `json:"updated_at"`

	// Department information
	FromDepartment DepartmentInfo `json:"from_department"`
	ToDepartment   DepartmentInfo `json:"to_department"`
}

type CreateDispositionRouteRequest struct {
	FromDepartmentID uuid.UUID               `json:"from_department_id" binding:"required"`
	ToDepartmentIDs  []uuid.UUID             `json:"to_department_ids" binding:"required,min=1"`
	IsActive         *bool                   `json:"is_active,omitempty"`
	AllowedActions   *map[string]interface{} `json:"allowed_actions,omitempty"`
}

// BulkCreateDispositionRouteResponse response for bulk create/update operation
type BulkCreateDispositionRouteResponse struct {
	Created int                        `json:"created"`
	Updated int                        `json:"updated"`
	Routes  []DispositionRouteResponse `json:"routes"`
}

type UpdateDispositionRouteRequest struct {
	IsActive       *bool                   `json:"is_active,omitempty"`
	AllowedActions *map[string]interface{} `json:"allowed_actions,omitempty"`
}

type ListDispositionRoutesResponse struct {
	Routes []DispositionRouteResponse `json:"routes"`
}

// DepartmentMapping represents department ID and name mapping
type DepartmentMapping struct {
	ID   uuid.UUID `json:"id"`
	Name string    `json:"name"`
}

// DispositionRouteGroupedItem represents a single grouped route item with clean department structure
type DispositionRouteGroupedItem struct {
	FromDepartment DepartmentMapping   `json:"from_department"`
	ToDepartments  []DepartmentMapping `json:"to_departments"`
}

// ListDispositionRoutesGroupedResponse returns all routes grouped by from_department_id
type ListDispositionRoutesGroupedResponse struct {
	Dispositions []DispositionRouteGroupedItem `json:"dispositions"`
}

// ListDispositionRoutesDetailedResponse returns all routes with department details
type ListDispositionRoutesDetailedResponse struct {
	Routes []DispositionRouteResponse `json:"routes"`
	Total  int                        `json:"total"`
}
