package org.tio.sitexxx.service.service.jpush.huawei.android;

import com.alibaba.fastjson.annotation.JSONField;
import org.tio.sitexxx.service.service.jpush.huawei.util.ValidatorUtils;

/**
 * <pre>
 *    @author : vagrancy
 *    e-mail : 18050829067@163.com
 *    time   : 2025-02-21 10:43
 *    desc   :
 * </pre>
 */
public class LightSettings {
    private static final String LIGTH_DURATION_PATTERN = "\\d+|\\d+[sS]|\\d+.\\d{1,9}|\\d+.\\d{1,9}[sS]";

    @JSONField(name = "color")
    private Color color;

    @JSONField(name = "light_on_duration")
    private String lightOnDuration;

    @JSONField(name = "light_off_duration")
    private String lightOffDuration;

    public LightSettings(Builder builder) {
        this.color = builder.color;
        this.lightOnDuration = builder.lightOnDuration;
        this.lightOffDuration = builder.lightOffDuration;
    }

    public Color getColor() {
        return color;
    }

    public String getLightOnDuration() {
        return lightOnDuration;
    }

    public String getLightOffDuration() {
        return lightOffDuration;
    }

    /**
     * 参数校验
     */
    public void check() {
        ValidatorUtils.checkArgument(this.color != null, "color must be selected when light_settings is set");

        if (this.color != null) {
            this.color.check();
        }

        ValidatorUtils.checkArgument(this.lightOnDuration != null, "light_on_duration must be selected when light_settings is set");

        ValidatorUtils.checkArgument(this.lightOffDuration != null, "light_off_duration must be selected when light_settings is set");

        ValidatorUtils.checkArgument(this.lightOnDuration.matches(LIGTH_DURATION_PATTERN), "light_on_duration format is wrong");

        ValidatorUtils.checkArgument(this.lightOffDuration.matches(LIGTH_DURATION_PATTERN), "light_off_duration format is wrong");
    }

    /**
     * builder
     */
    public static Builder builder() {
        return new Builder();
    }

    public static class Builder {
        private Color color;
        private String lightOnDuration;
        private String lightOffDuration;

        public Builder setColor(Color color) {
            this.color = color;
            return this;
        }

        public Builder setLightOnDuration(String lightOnDuration) {
            this.lightOnDuration = lightOnDuration;
            return this;
        }

        public Builder setLightOffDuration(String lightOffDuration) {
            this.lightOffDuration = lightOffDuration;
            return this;
        }

        public LightSettings build() {
            return new LightSettings(this);
        }
    }

}
