package council

import (
	"time"

	"github.com/google/uuid"
)

// CouncilFormationRequest represents a request to form a project kickoff council
type CouncilFormationRequest struct {
	ProjectName      string            `json:"project_name"`
	Repository       string            `json:"repository"`
	ProjectBrief     string            `json:"project_brief"`
	Constraints      string            `json:"constraints,omitempty"`
	TechLimits       string            `json:"tech_limits,omitempty"`
	ComplianceNotes  string            `json:"compliance_notes,omitempty"`
	Targets          string            `json:"targets,omitempty"`
	TaskID           uuid.UUID         `json:"task_id"`
	IssueID          int64             `json:"issue_id"`
	ExternalURL      string            `json:"external_url"`
	GoalID           string            `json:"goal_id,omitempty"`
	PulseID          string            `json:"pulse_id,omitempty"`
	Metadata         map[string]interface{} `json:"metadata,omitempty"`
}

// CouncilComposition defines the agents that make up the kickoff council
type CouncilComposition struct {
	CouncilID       uuid.UUID           `json:"council_id"`
	ProjectName     string              `json:"project_name"`
	CoreAgents      []CouncilAgent      `json:"core_agents"`
	OptionalAgents  []CouncilAgent      `json:"optional_agents"`
	CreatedAt       time.Time           `json:"created_at"`
	Status          string              `json:"status"` // forming, active, completed, failed
}

// CouncilAgent represents a single agent in the council
type CouncilAgent struct {
	AgentID          string    `json:"agent_id"`
	RoleName         string    `json:"role_name"`
	AgentName        string    `json:"agent_name"`
	Required         bool      `json:"required"`
	Deployed         bool      `json:"deployed"`
	ServiceID        string    `json:"service_id,omitempty"`
	DeployedAt       *time.Time `json:"deployed_at,omitempty"`
	Status           string    `json:"status"` // pending, assigned, deploying, active, failed
	PersonaStatus    *string   `json:"persona_status,omitempty"` // pending, loading, loaded, failed
	PersonaLoadedAt  *time.Time `json:"persona_loaded_at,omitempty"`
	EndpointURL      *string   `json:"endpoint_url,omitempty"`
	PersonaAckPayload map[string]interface{} `json:"persona_ack_payload,omitempty"`
}

// CouncilDeploymentResult represents the result of council agent deployment
type CouncilDeploymentResult struct {
	CouncilID           uuid.UUID           `json:"council_id"`
	ProjectName         string              `json:"project_name"`
	DeployedAgents      []DeployedCouncilAgent `json:"deployed_agents"`
	Status              string              `json:"status"` // success, partial, failed
	Message             string              `json:"message"`
	DeployedAt          time.Time           `json:"deployed_at"`
	Errors              []string            `json:"errors,omitempty"`
}

// DeployedCouncilAgent represents a successfully deployed council agent
type DeployedCouncilAgent struct {
	ServiceID       string    `json:"service_id"`
	ServiceName     string    `json:"service_name"`
	RoleName        string    `json:"role_name"`
	AgentID         string    `json:"agent_id"`
	Image           string    `json:"image"`
	Status          string    `json:"status"`
	DeployedAt      time.Time `json:"deployed_at"`
}

// CouncilArtifacts represents the outputs produced by the council
type CouncilArtifacts struct {
	CouncilID           uuid.UUID         `json:"council_id"`
	ProjectName         string            `json:"project_name"`
	KickoffManifest     map[string]interface{} `json:"kickoff_manifest,omitempty"`
	SeminalDR           string            `json:"seminal_dr,omitempty"`
	ScaffoldPlan        map[string]interface{} `json:"scaffold_plan,omitempty"`
	GateTests           string            `json:"gate_tests,omitempty"`
	CHORUSLinks         map[string]string `json:"chorus_links,omitempty"`
	ProducedAt          time.Time         `json:"produced_at"`
	Status              string            `json:"status"` // pending, partial, complete
}

// CoreCouncilRoles defines the required roles for any project kickoff council
// Reduced to minimal set for faster formation and easier debugging
var CoreCouncilRoles = []string{
	"tpm",
	"senior-software-architect",
}

// OptionalCouncilRoles defines the optional roles that may be included based on project needs
var OptionalCouncilRoles = []string{
	"data-ai-architect",
	"privacy-data-governance-officer", 
	"compliance-legal-liaison",
	"performance-benchmarking-analyst",
	"ui-ux-designer",
	"ios-macos-developer",
	"engine-programmer",
	"integration-architect",
	"cost-licensing-steward",
}