package contract

import (
	"time"

	"github.com/google/uuid"
)

type CreateVoteEventRequest struct {
	Title       string    `json:"title" validate:"required,min=1,max=255"`
	Description string    `json:"description"`
	StartDate   time.Time `json:"start_date" validate:"required"`
	EndDate     time.Time `json:"end_date" validate:"required"`
	ResultsOpen *bool     `json:"results_open,omitempty"`
}

type UpdateVoteEventRequest struct {
	Title       string    `json:"title" validate:"required,min=1,max=255"`
	Description string    `json:"description"`
	StartDate   time.Time `json:"start_date" validate:"required"`
	EndDate     time.Time `json:"end_date" validate:"required"`
	IsActive    bool      `json:"is_active"`
	ResultsOpen *bool     `json:"results_open,omitempty"`
}

type VoteEventResponse struct {
	ID          uuid.UUID           `json:"id"`
	Title       string              `json:"title"`
	Description string              `json:"description"`
	StartDate   time.Time           `json:"start_date"`
	EndDate     time.Time           `json:"end_date"`
	IsActive    bool                `json:"is_active"`
	ResultsOpen bool                `json:"results_open"`
	IsVotingOpen bool               `json:"is_voting_open"`
	CreatedAt   time.Time           `json:"created_at"`
	UpdatedAt   time.Time           `json:"updated_at"`
	Candidates  []CandidateResponse `json:"candidates,omitempty"`
}

type ListVoteEventsRequest struct {
	Page  int `json:"page" validate:"min=1"`
	Limit int `json:"limit" validate:"min=1,max=100"`
}

type ListVoteEventsResponse struct {
	VoteEvents []VoteEventResponse `json:"vote_events"`
	Pagination PaginationResponse  `json:"pagination"`
}

type CreateCandidateRequest struct {
	VoteEventID uuid.UUID `json:"vote_event_id" validate:"required"`
	Name        string    `json:"name" validate:"required,min=1,max=255"`
	ImageURL    string    `json:"image_url"`
	Description string    `json:"description"`
}

type CandidateResponse struct {
	ID          uuid.UUID `json:"id"`
	VoteEventID uuid.UUID `json:"vote_event_id"`
	Name        string    `json:"name"`
	ImageURL    string    `json:"image_url"`
	Description string    `json:"description"`
	CreatedAt   time.Time `json:"created_at"`
	UpdatedAt   time.Time `json:"updated_at"`
	VoteCount   int64     `json:"vote_count,omitempty"`
}

type SubmitVoteRequest struct {
	VoteEventID uuid.UUID `json:"vote_event_id" validate:"required"`
	CandidateID uuid.UUID `json:"candidate_id" validate:"required"`
}

type VoteResponse struct {
	ID          uuid.UUID `json:"id"`
	VoteEventID uuid.UUID `json:"vote_event_id"`
	CandidateID uuid.UUID `json:"candidate_id"`
	UserID      uuid.UUID `json:"user_id"`
	CreatedAt   time.Time `json:"created_at"`
}

type VoteResultsResponse struct {
	VoteEventID uuid.UUID                    `json:"vote_event_id"`
	Candidates  []CandidateWithVotesResponse `json:"candidates"`
	TotalVotes  int64                        `json:"total_votes"`
}

type CandidateWithVotesResponse struct {
	CandidateResponse
	VoteCount int64 `json:"vote_count"`
}

type CheckVoteStatusResponse struct {
	HasVoted    bool      `json:"has_voted"`
	VotedAt     *time.Time `json:"voted_at,omitempty"`
	CandidateID *uuid.UUID `json:"candidate_id,omitempty"`
}