/*
 * Orvanta API
 *
 * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
 *
 * The version of the OpenAPI document: 1.2.0
 * Contact: contact@orvanta.cloud
 * Generated by: https://openapi-generator.tech
 */

use crate::models;
use serde::{Deserialize, Serialize};

#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
pub struct Schedule {
    /// The unique Orvanta path for this schedule. Must be of the form `u/<user>/<path>` or `f/<folder>/<path>`.
    #[serde(rename = "path")]
    pub path: String,
    /// Username of the last person who edited this schedule
    #[serde(rename = "edited_by")]
    pub edited_by: String,
    /// Timestamp of the last edit
    #[serde(rename = "edited_at")]
    pub edited_at: String,
    /// Cron expression with 6 fields (seconds, minutes, hours, day of month, month, day of week). Example '0 0 12 * * *' for daily at noon
    #[serde(rename = "schedule")]
    pub schedule: String,
    /// IANA timezone for the schedule (e.g., 'UTC', 'Europe/Paris', 'America/New_York')
    #[serde(rename = "timezone")]
    pub timezone: String,
    /// Whether the schedule is currently active and will trigger jobs
    #[serde(rename = "enabled")]
    pub enabled: bool,
    /// Path to the script or flow to execute when triggered
    #[serde(rename = "script_path")]
    pub script_path: String,
    /// True if script_path points to a flow, false if it points to a script
    #[serde(rename = "is_flow")]
    pub is_flow: bool,
    /// The arguments to pass to the script or flow
    #[serde(rename = "args", skip_serializing_if = "Option::is_none")]
    pub args: Option<std::collections::HashMap<String, serde_json::Value>>,
    /// Additional permissions for this schedule
    #[serde(rename = "extra_perms")]
    pub extra_perms: std::collections::HashMap<String, bool>,
    /// Email of the user who owns this schedule, used for permissioned_as
    #[serde(rename = "email")]
    pub email: String,
    /// The user or group this schedule runs as (e.g., 'u/admin' or 'g/mygroup')
    #[serde(rename = "permissioned_as")]
    pub permissioned_as: String,
    /// Last error message if the schedule failed to trigger
    #[serde(rename = "error", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
    pub error: Option<Option<String>>,
    /// Path to a script or flow to run when the scheduled job fails
    #[serde(rename = "on_failure", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
    pub on_failure: Option<Option<String>>,
    /// Number of consecutive failures before the on_failure handler is triggered (default 1)
    #[serde(rename = "on_failure_times", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
    pub on_failure_times: Option<Option<f64>>,
    /// If true, trigger on_failure handler only on exactly N failures, not on every failure after N
    #[serde(rename = "on_failure_exact", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
    pub on_failure_exact: Option<Option<bool>>,
    /// The arguments to pass to the script or flow
    #[serde(rename = "on_failure_extra_args", skip_serializing_if = "Option::is_none")]
    pub on_failure_extra_args: Option<std::collections::HashMap<String, serde_json::Value>>,
    /// Path to a script or flow to run when the schedule recovers after failures
    #[serde(rename = "on_recovery", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
    pub on_recovery: Option<Option<String>>,
    /// Number of consecutive successes before the on_recovery handler is triggered (default 1)
    #[serde(rename = "on_recovery_times", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
    pub on_recovery_times: Option<Option<f64>>,
    /// The arguments to pass to the script or flow
    #[serde(rename = "on_recovery_extra_args", skip_serializing_if = "Option::is_none")]
    pub on_recovery_extra_args: Option<std::collections::HashMap<String, serde_json::Value>>,
    /// Path to a script or flow to run after each successful execution
    #[serde(rename = "on_success", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
    pub on_success: Option<Option<String>>,
    /// The arguments to pass to the script or flow
    #[serde(rename = "on_success_extra_args", skip_serializing_if = "Option::is_none")]
    pub on_success_extra_args: Option<std::collections::HashMap<String, serde_json::Value>>,
    /// If true, the workspace-level error handler will not be triggered for this schedule's failures
    #[serde(rename = "ws_error_handler_muted", skip_serializing_if = "Option::is_none")]
    pub ws_error_handler_muted: Option<bool>,
    #[serde(rename = "retry", skip_serializing_if = "Option::is_none")]
    pub retry: Option<Box<models::Retry>>,
    /// Short summary describing the purpose of this schedule
    #[serde(rename = "summary", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
    pub summary: Option<Option<String>>,
    /// Detailed description of what this schedule does
    #[serde(rename = "description", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
    pub description: Option<Option<String>>,
    /// If true, skip this schedule's execution if the previous run is still in progress (prevents concurrent runs)
    #[serde(rename = "no_flow_overlap", skip_serializing_if = "Option::is_none")]
    pub no_flow_overlap: Option<bool>,
    /// Worker tag to route jobs to specific worker groups
    #[serde(rename = "tag", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
    pub tag: Option<Option<String>>,
    /// ISO 8601 datetime until which the schedule is paused. Schedule resumes automatically after this time
    #[serde(rename = "paused_until", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
    pub paused_until: Option<Option<String>>,
    /// Cron parser version. Use 'v2' for extended syntax with additional features
    #[serde(rename = "cron_version", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
    pub cron_version: Option<Option<String>>,
    /// Path to a script that validates scheduled datetimes. Receives scheduled_for datetime and returns boolean to skip (true) or run (false)
    #[serde(rename = "dynamic_skip", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
    pub dynamic_skip: Option<Option<String>>,
    #[serde(rename = "labels", skip_serializing_if = "Option::is_none")]
    pub labels: Option<Vec<String>>,
}

impl Schedule {
    pub fn new(path: String, edited_by: String, edited_at: String, schedule: String, timezone: String, enabled: bool, script_path: String, is_flow: bool, extra_perms: std::collections::HashMap<String, bool>, email: String, permissioned_as: String) -> Schedule {
        Schedule {
            path,
            edited_by,
            edited_at,
            schedule,
            timezone,
            enabled,
            script_path,
            is_flow,
            args: None,
            extra_perms,
            email,
            permissioned_as,
            error: None,
            on_failure: None,
            on_failure_times: None,
            on_failure_exact: None,
            on_failure_extra_args: None,
            on_recovery: None,
            on_recovery_times: None,
            on_recovery_extra_args: None,
            on_success: None,
            on_success_extra_args: None,
            ws_error_handler_muted: None,
            retry: None,
            summary: None,
            description: None,
            no_flow_overlap: None,
            tag: None,
            paused_until: None,
            cron_version: None,
            dynamic_skip: None,
            labels: None,
        }
    }
}

