package cn.novalon.gym.manage.sys.core.command;

import cn.novalon.gym.manage.common.exception.ErrorCode;
import cn.novalon.gym.manage.common.exception.ValidationException;

/**
 * 创建公告命令对象
 * 
 * @author 张翔
 * @date 2026-03-13
 */
public record CreateNoticeCommand(
        String noticeTitle,
        String noticeContent,
        String noticeType,
        String status) {
    public static CreateNoticeCommand of(String noticeTitle, String noticeContent, String noticeType, String status) {
        validateNoticeTitle(noticeTitle);
        validateNoticeContent(noticeContent);
        validateNoticeType(noticeType);
        return new CreateNoticeCommand(noticeTitle, noticeContent, noticeType, status);
    }

    private static void validateNoticeTitle(String noticeTitle) {
        if (noticeTitle == null || noticeTitle.trim().isEmpty()) {
            throw new ValidationException(ErrorCode.VALIDATION_REQUIRED, "Notice title is required");
        }
    }

    private static void validateNoticeContent(String noticeContent) {
        if (noticeContent == null || noticeContent.trim().isEmpty()) {
            throw new ValidationException(ErrorCode.VALIDATION_REQUIRED, "Notice content is required");
        }
    }

    private static void validateNoticeType(String noticeType) {
        if (noticeType != null && !noticeType.equals("1") && !noticeType.equals("2")) {
            throw new ValidationException(ErrorCode.VALIDATION_INVALID_VALUE,
                    "Invalid notice type. Notice type must be 1 (notification) or 2 (announcement)");
        }
    }
}
