
package com.cygnusa.hyperm.training.activities;

import com.cygnusa.hyperm.wrappers.DSE;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
import java.util.Objects;

public class Schedules {

    private String id;
    private String title;
    private String description;
    private String fromdate;
    private String todate;
    private String organiser_name;
    private String channel;
    private String organiser;
    private String status;
    private String is_deleted;
    private String organiser_role;
    private ArrayList<DSE> userlist;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getFromdate() {
        return fromdate;
    }

    public void setFromdate(String fromdate) {
        this.fromdate = fromdate;
    }

    public String getTodate() {
        return todate;
    }

    public void setTodate(String todate) {
        this.todate = todate;
    }

    public String getOrganiser_name() {
        return organiser_name;
    }

    public void setOrganiser_name(String organiser_name) {
        this.organiser_name = organiser_name;
    }

    public String getChannel() {
        return channel;
    }

    public void setChannel(String channel) {
        this.channel = channel;
    }

    public String getOrganiser() {
        return organiser == null ? "" : organiser;
    }

    public void setOrganiser(String organiser) {
        this.organiser = organiser;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public String getIs_deleted() {
        return is_deleted;
    }

    public void setIs_deleted(String is_deleted) {
        this.is_deleted = is_deleted;
    }

    public String getOrganiser_role() {
        return organiser_role;
    }

    public void setOrganiser_role(String organiser_role) {
        this.organiser_role = organiser_role;
    }

    public ArrayList<DSE> getUserlist() {
        return userlist == null ? new ArrayList<>() : userlist;
    }

    public void setUserlist(ArrayList<DSE> userlist) {
        this.userlist = userlist;
    }

    public boolean isValidTime() {
        try {
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault());
            Date min = format.parse(fromdate);
            Date max = format.parse(todate);
            Date d = new Date();
            return d.after(min) && d.before(max);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }

    boolean isValidTime(boolean isPresendor) {
        try {
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault());
            Date min = format.parse(fromdate);
            if (isPresendor) {
                Calendar calendar = Calendar.getInstance();
                calendar.setTime(Objects.requireNonNull(min));
                long t = calendar.getTimeInMillis();
                min = new Date(t - (5 * 60000));
            }
            Date max = format.parse(todate);
            Date d = new Date();
            return d.after(min) && d.before(max);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }

    public boolean isEnded() {
        try {
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault());
            Date max = format.parse(todate);
            Date d = new Date();
            return d.after(max);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }

    public String getDate() {
        try {
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault());
            Date date = format.parse(fromdate);
            return new SimpleDateFormat("dd", Locale.getDefault()).format(Objects.requireNonNull(date));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "00";
    }

    public String getMonth() {
        try {
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault());
            Date date = format.parse(fromdate);
            return new SimpleDateFormat("MMM", Locale.getDefault()).format(Objects.requireNonNull(date)).toUpperCase();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "";
    }

    public String getTime() {
        try {
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault());
            Date date = format.parse(fromdate);
            Date date1 = format.parse(todate);
            String mDate = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault()).format(Objects.requireNonNull(date));
            String fTime = new SimpleDateFormat("hh:mm a", Locale.getDefault()).format(Objects.requireNonNull(date));
            String tTime = new SimpleDateFormat("hh:mm a", Locale.getDefault()).format(Objects.requireNonNull(date1));
            return fTime + " - " + tTime;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "00:00 - 00:00";
    }

    public String getDateTime() {
        try {
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault());
            Date date = format.parse(fromdate);
            Date date1 = format.parse(todate);
            String mDate = new SimpleDateFormat("dd-MMM-yyyy", Locale.getDefault()).format(Objects.requireNonNull(date));
            String fTime = new SimpleDateFormat("hh:mm a", Locale.getDefault()).format(Objects.requireNonNull(date));
            String tTime = new SimpleDateFormat("hh:mm a", Locale.getDefault()).format(Objects.requireNonNull(date1));
            return mDate + ", " + fTime + " to " + tTime;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "00:00 - 00:00";
    }
}
