import { z } from 'zod';
export const DurationSchema = z.number().int().nonnegative();
export class Duration {
    milliseconds;
    constructor(milliseconds) {
        this.milliseconds = milliseconds;
    }
    static fromMilliseconds(ms) {
        const validated = DurationSchema.parse(ms);
        return new Duration(validated);
    }
    static fromSeconds(seconds) {
        return new Duration(Math.round(seconds * 1000));
    }
    static fromMinutes(minutes) {
        return new Duration(Math.round(minutes * 60 * 1000));
    }
    static zero() {
        return new Duration(0);
    }
    get ms() {
        return this.milliseconds;
    }
    get seconds() {
        return Math.floor(this.milliseconds / 1000);
    }
    get minutes() {
        return Math.floor(this.milliseconds / 60000);
    }
    get formatted() {
        const totalSeconds = this.seconds;
        const mins = Math.floor(totalSeconds / 60);
        const secs = totalSeconds % 60;
        if (mins === 0)
            return `${secs}s`;
        if (secs === 0)
            return `${mins}m`;
        return `${mins}m ${secs}s`;
    }
    add(other) {
        return new Duration(this.milliseconds + other.milliseconds);
    }
    subtract(other) {
        const result = this.milliseconds - other.milliseconds;
        return new Duration(Math.max(0, result));
    }
    isGreaterThan(other) {
        return this.milliseconds > other.milliseconds;
    }
    equals(other) {
        return this.milliseconds === other.milliseconds;
    }
    toJSON() {
        return this.milliseconds;
    }
    toString() {
        return this.formatted;
    }
}
//# sourceMappingURL=duration.valueObject.js.map