package models

import (
	"time"

	"gorm.io/datatypes"
)

type Exam struct {
	ID        string     `json:"id" db:"id" example:"ef74c59a-c707-4162-a52b-455906c81ec1" gorm:"column:id;size:255;primary_key;"`
	ProgramID string     `json:"program_id" db:"program_id" example:"7f9329f5-2e36-4638-92d2-73064b7291a4" gorm:"column:program_id;size:255;uniqueIndex:idx_exam;"`
	UserID    string     `json:"user_id" db:"user_id" example:"f95159dd-c42c-490d-ac6b-ca5d88a266bb" gorm:"column:user_id;size:255;uniqueIndex:idx_exam;"`
	Subject   string     `json:"subject" db:"subject" example:"출력 Print" gorm:"column:subject;size:255;index;"`
	Program   string     `json:"program" db:"program" example:"파이썬 초급 과정" gorm:"column:program;size:255;index;"`
	Name      string     `json:"name" db:"name" example:"홍길순" gorm:"column:name;size:255;index;"`
	Score     int        `json:"score" db:"score" example:"5" gorm:"column:score;"`
	Total     int        `json:"total" db:"total" example:"5" gorm:"column:total;"`
	Status    string     `json:"status" example:"ready" gorm:"column:status;size:10;index;"`
	StartAt   *time.Time `json:"start_at" gorm:"column:start_at;index;"`
	EndAt     *time.Time `json:"end_at" gorm:"column:end_at;index;"`
	UpdatedAt time.Time  `json:"-" gorm:"column:updated_at;type:DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP;index;->:false"`
	CreatedAt time.Time  `json:"-" gorm:"column:created_at;type:DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP;index;->:false;<-:create"`
}

type ExamRequest struct {
	ProgramID string         `json:"program_id" example:"7f9329f5-2e36-4638-92d2-73064b7291a4"`
	Users     datatypes.JSON `json:"users"`
}

type ExamResponse struct {
	ID        string `json:"id" db:"id" example:"ef74c59a-c707-4162-a52b-455906c81ec1"`
	ProgramID string `json:"program_id" example:"7f9329f5-2e36-4638-92d2-73064b7291a4"`
	UserID    string `json:"user_id" example:"f95159dd-c42c-490d-ac6b-ca5d88a266bb"`
	Subject   string `json:"subject" example:"출력 Print"`
	Program   string `json:"program" example:"파이썬 초급 과정"`
	Name      string `json:"name" example:"홍길순"`
	Score     int    `json:"score" example:"5"`
	Total     int    `json:"total" example:"5"`
	Status    string `json:"status" example:"ready"`
	StartAt   string `json:"start_at,omitempty" example:"2023-11-10T13:10:00+09:00"`
	EndAt     string `json:"end_at,omitempty" example:"2023-11-10T13:25:00+09:00"`
}

type ExamUpdateRequest struct {
	ProgramID string `json:"program_id" example:"7f9329f5-2e36-4638-92d2-73064b7291a4"`
	UserID    string `json:"user_id" example:"f95159dd-c42c-490d-ac6b-ca5d88a266bb"`
	Subject   string `json:"subject" example:"출력 Print"`
	Program   string `json:"program" example:"파이썬 초급 과정"`
	Name      string `json:"name" example:"홍길순"`
	Score     int    `json:"score" example:"5"`
	Total     int    `json:"total" example:"5"`
	Status    string `json:"status" example:"ready"`
	StartAt   string `json:"start_at,omitempty" example:"2023-11-10T13:10:00+09:00"`
	EndAt     string `json:"end_at,omitempty" example:"2023-11-10T13:25:00+09:00"`
}

type ExamPatchRequest struct {
	Score   int    `json:"score,omitempty" example:"4"`
	Status  string `json:"status,omitempty" example:"rating"`
	StartAt string `json:"start_at,omitempty" example:"2023-11-10T13:10:00+09:00"`
	EndAt   string `json:"end_at,omitempty" example:"2023-11-10T13:25:00+09:00"`
}

type ExamListResponse struct {
	Data      []Exam `json:"data"`
	Total     int64  `json:"total" example:"999"`
	Page      int    `json:"page" example:"1"`
	TotalPage int64  `json:"totalPage" example:"99"`
	PageSize  int    `json:"pageSize" example:"10"`
}
