package com.example.demo.model;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotNull;

@Entity
@Table(name = "system_settings")
public class SystemSettings {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    /** 每次生成消耗的资源点数量 */
    @NotNull
    @Min(0)
    @Column(nullable = false)
    private Integer pointsPerGeneration = 1;

    /** 站点名称 */
    @Column(nullable = false, length = 100)
    private String siteName = "AIGC Demo";

    /** 站点副标题 */
    @Column(nullable = false, length = 150)
    private String siteSubtitle = "现代化的Spring Boot应用演示";

    /** 是否开放注册 */
    @NotNull
    @Column(nullable = false)
    private Boolean registrationOpen = true;

    /** 维护模式开关 */
    @NotNull
    @Column(nullable = false)
    private Boolean maintenanceMode = false;

    /** 支付渠道开关 */
    @NotNull
    @Column(nullable = false)
    private Boolean enableAlipay = true;

    @NotNull
    @Column(nullable = false)
    private Boolean enablePaypal = true;

    /** 联系邮箱 */
    @Column(length = 120)
    private String contactEmail = "support@example.com";

    /** 优化提示词使用的模型 */
    @Column(length = 50)
    private String promptOptimizationModel = "gpt-5.1-thinking";

    /** 分镜图生成系统引导词 */
    @Column(length = 2000)
    private String storyboardSystemPrompt = "";

    /** Token过期时间（小时），范围1-720小时，默认720小时(30天) */
    @NotNull
    @Min(1)
    @Column(nullable = false)
    private Integer tokenExpireHours = 720;

    /** AI API密钥（视频和图片生成共用） */
    @Column(length = 200)
    private String aiApiKey;

    /** AI API基础URL */
    @Column(length = 200)
    private String aiApiBaseUrl;

    /** 文生视频消耗资源点 */
    @NotNull
    @Min(0)
    @Column(nullable = false)
    private Integer textToVideoPoints = 30;

    /** 图生视频消耗资源点 */
    @NotNull
    @Min(0)
    @Column(nullable = false)
    private Integer imageToVideoPoints = 30;

    /** 分镜图生成消耗资源点 */
    @NotNull
    @Min(0)
    @Column(nullable = false)
    private Integer storyboardImagePoints = 30;

    /** 分镜视频生成消耗资源点 */
    @NotNull
    @Min(0)
    @Column(nullable = false)
    private Integer storyboardVideoPoints = 30;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Integer getPointsPerGeneration() {
        return pointsPerGeneration;
    }

    public void setPointsPerGeneration(Integer pointsPerGeneration) {
        this.pointsPerGeneration = pointsPerGeneration;
    }

    public String getSiteName() {
        return siteName;
    }

    public void setSiteName(String siteName) {
        this.siteName = siteName;
    }

    public String getSiteSubtitle() {
        return siteSubtitle;
    }

    public void setSiteSubtitle(String siteSubtitle) {
        this.siteSubtitle = siteSubtitle;
    }

    public Boolean getRegistrationOpen() {
        return registrationOpen;
    }

    public void setRegistrationOpen(Boolean registrationOpen) {
        this.registrationOpen = registrationOpen;
    }

    public Boolean getMaintenanceMode() {
        return maintenanceMode;
    }

    public void setMaintenanceMode(Boolean maintenanceMode) {
        this.maintenanceMode = maintenanceMode;
    }

    public Boolean getEnableAlipay() {
        return enableAlipay;
    }

    public void setEnableAlipay(Boolean enableAlipay) {
        this.enableAlipay = enableAlipay;
    }

    public Boolean getEnablePaypal() {
        return enablePaypal;
    }

    public void setEnablePaypal(Boolean enablePaypal) {
        this.enablePaypal = enablePaypal;
    }

    public String getContactEmail() {
        return contactEmail;
    }

    public void setContactEmail(String contactEmail) {
        this.contactEmail = contactEmail;
    }

    public String getPromptOptimizationModel() {
        return promptOptimizationModel;
    }

    public void setPromptOptimizationModel(String promptOptimizationModel) {
        this.promptOptimizationModel = promptOptimizationModel;
    }

    public String getStoryboardSystemPrompt() {
        return storyboardSystemPrompt;
    }

    public void setStoryboardSystemPrompt(String storyboardSystemPrompt) {
        this.storyboardSystemPrompt = storyboardSystemPrompt;
    }

    public Integer getTokenExpireHours() {
        return tokenExpireHours;
    }

    public void setTokenExpireHours(Integer tokenExpireHours) {
        // 限制范围在1-720小时（1小时到30天）
        if (tokenExpireHours != null && tokenExpireHours >= 1 && tokenExpireHours <= 720) {
            this.tokenExpireHours = tokenExpireHours;
        } else if (tokenExpireHours != null) {
            // 值超出范围时，强制设置为边界值
            if (tokenExpireHours < 1) {
                this.tokenExpireHours = 1;
            } else {
                this.tokenExpireHours = 720;
            }
        }
    }

    public String getAiApiKey() {
        return aiApiKey;
    }

    public void setAiApiKey(String aiApiKey) {
        this.aiApiKey = aiApiKey;
    }

    public String getAiApiBaseUrl() {
        return aiApiBaseUrl;
    }

    public void setAiApiBaseUrl(String aiApiBaseUrl) {
        this.aiApiBaseUrl = aiApiBaseUrl;
    }

    public Integer getTextToVideoPoints() {
        return textToVideoPoints;
    }

    public void setTextToVideoPoints(Integer textToVideoPoints) {
        this.textToVideoPoints = textToVideoPoints;
    }

    public Integer getImageToVideoPoints() {
        return imageToVideoPoints;
    }

    public void setImageToVideoPoints(Integer imageToVideoPoints) {
        this.imageToVideoPoints = imageToVideoPoints;
    }

    public Integer getStoryboardImagePoints() {
        return storyboardImagePoints;
    }

    public void setStoryboardImagePoints(Integer storyboardImagePoints) {
        this.storyboardImagePoints = storyboardImagePoints;
    }

    public Integer getStoryboardVideoPoints() {
        return storyboardVideoPoints;
    }

    public void setStoryboardVideoPoints(Integer storyboardVideoPoints) {
        this.storyboardVideoPoints = storyboardVideoPoints;
    }
}


