use actix_web::{web, Responder};
use askama_actix::TemplateToResponse;
use chrono::NaiveDate;
use serde::Deserialize;

use crate::endpoints::availability::NewOrEditAvailabilityTemplate;
use crate::models::User;

#[derive(Deserialize)]
struct AvailabilityNewQuery {
    #[serde(rename(deserialize = "wholeday"))]
    whole_day: Option<bool>,
    date: NaiveDate,
}

#[actix_web::get("/availabillity/new")]
pub async fn get(
    user: web::ReqData<User>,
    query: web::Query<AvailabilityNewQuery>,
) -> impl Responder {
    let template = NewOrEditAvailabilityTemplate {
        user: user.into_inner(),
        date: query.date,
        whole_day: query.whole_day.unwrap_or(true),
        id: None,
        start_time: None,
        end_time: None,
        comment: None,
    };

    template.to_response()
}
