"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.EMPTY_DATE = exports.END_DATE = exports.START_DATE = exports.PurpleDate = void 0;
class PurpleDate {
    constructor(params) {
        this.isToday = () => {
            return (this.today.year === this.year && this.today.month === this.month && this.today.dateOfMonth === this.dateOfMonth);
        };
        this.toDateString = (format = 'YYYY.MM.DD', seperator = '.') => {
            const month = (() => {
                if (this.month < 10) {
                    return `0${this.month}`;
                }
                else {
                    return this.month;
                }
            })();
            const dateOfMonth = (() => {
                if (this.dateOfMonth < 10) {
                    return `0${this.dateOfMonth}`;
                }
                else {
                    return this.dateOfMonth;
                }
            })();
            switch (format) {
                case 'YYYY.MM.DD':
                    return `${this.year}${seperator}${month}${seperator}${dateOfMonth}`;
                case 'YY.MM.DD':
                    return `${String(this.year).slice(2, 4)}${seperator}${month}${seperator}${dateOfMonth}`;
                default:
                    return '지원되지 않는 형식입니다.';
            }
        };
        this.addMonth = (months) => {
            // fyi. 윤달, -값 계산등의 버그가 없도록 date 연산에 기대었습니다.
            const d = new Date(this.year, this.indexOfMonth + months, this.dateOfMonth);
            // return this;
            return new PurpleDate([d.getFullYear(), d.getMonth() + 1, d.getDate()]);
        };
        this.addYear = (years) => {
            // fyi. 윤달, -값 계산등의 버그가 없도록 date 연산에 기대었습니다.
            const d = new Date(this.year + years, this.indexOfMonth, this.dateOfMonth);
            // return this;
            return new PurpleDate([d.getFullYear(), d.getMonth() + 1, d.getDate()]);
        };
        // TODO: invalid date 검증 필요
        let d;
        if (!params) {
            d = new Date();
        }
        else {
            const [year, month, dateOfMonth] = params;
            d = new Date(year, month - 1, dateOfMonth); // fyi. date 연산 후 값 사용
        }
        this.year = d.getFullYear();
        this.month = d.getMonth() + 1;
        this.indexOfMonth = d.getMonth();
        this.dateOfMonth = d.getDate();
        this.indexOfDayOfWeek = d.getDay();
        this.timestamp = Date.parse(`${this.year}-${this.month}-${this.dateOfMonth}`);
    }
    get today() {
        const d = new Date();
        return new PurpleDate([d.getFullYear(), d.getMonth() + 1, d.getDate()]);
    }
}
exports.PurpleDate = PurpleDate;
const START_DATE = new PurpleDate([1, 12, 31]);
exports.START_DATE = START_DATE;
const END_DATE = new PurpleDate([9999, 12, 31]);
exports.END_DATE = END_DATE;
const EMPTY_DATE = null;
exports.EMPTY_DATE = EMPTY_DATE;
