﻿using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using SaltEdge.Utils;

namespace SaltEdge.Models
{
    public class SELogin : IComparable
    {
        [JsonProperty(PropertyName = SEConstants.KEY_ID)]
        public int Id { get; set; }

        [JsonProperty(PropertyName = SEConstants.KEY_SECRET)]
        public string Secret { get; set; }

        [JsonProperty(PropertyName = SEConstants.KEY_FINISHED)]
        private bool IsFinished { get; set; }

        [JsonProperty(PropertyName = SEConstants.KEY_FINISHED_RECENT)]
        private bool IsFinishedRecent { get; set; }

        [JsonProperty(PropertyName = SEConstants.KEY_PARTIAL)]
        private bool Partial { get; set; }

        [JsonProperty(PropertyName = SEConstants.KEY_PROVIDER_CODE)]
        private string ProviderCode { get; set; }

        [JsonProperty(PropertyName = SEConstants.KEY_PROVIDER_NAME)]
        private string ProviderName { get; set; }

        [JsonProperty(PropertyName = SEConstants.KEY_AUTOMATIC_FETCH)]
        private bool AutomaticFetch { get; set; }

        [JsonProperty(PropertyName = SEConstants.KEY_INTERACTIVE)]
        private bool IsInteractive { get; set; }

        [JsonProperty(PropertyName = SEConstants.KEY_INTERACTIVE_HTML)]
        private string InteractiveHtml { get; set; }

        [JsonProperty(PropertyName = SEConstants.KEY_INTERACTIVE_FIELDS_NAMES)]
        private List<string> InteractiveFieldsNames { get; set; }

        [JsonProperty(PropertyName = SEConstants.KEY_CUSTOMER_EMAIL)]
        private string CustomerEmail { get; set; }

        [JsonProperty(PropertyName = SEConstants.KEY_CREATED_AT)]
        private DateTime CreatedAt { get; set; }

        [JsonProperty(PropertyName = SEConstants.KEY_UPDATED_AT)]
        private DateTime UpdatedAt { get; set; }

        [JsonProperty(PropertyName = SEConstants.KEY_LAST_FAIL_AT)]
        private DateTime? LastFailAt { get; set; }

        [JsonProperty(PropertyName = SEConstants.KEY_LAST_REQUEST_AT)]
        private DateTime LastRequestAt { get; set; }

        [JsonProperty(PropertyName = SEConstants.KEY_LAST_FAIL_MESSAGE)]
        private string LastFailMessage { get; set; }

        [JsonProperty(PropertyName = SEConstants.KEY_LAST_SUCCESS_AT)]
        private DateTime LastSuccessAt { get; set; }

        [JsonProperty(PropertyName = SEConstants.KEY_STATUS)]
        private string Status { get; set; }

        [JsonProperty(PropertyName = SEConstants.KEY_STAGE)]
        private string Stage { get; set; }

        [JsonProperty(PropertyName = SEConstants.KEY_COUNTRY_CODE)]
        private string CountryCode { get; set; }

        public bool Equals(SELogin obj)
        {
            return obj != null && Id == obj.Id;
        }

        public int CompareTo(object obj)
        {
            var orderToCompare = obj as SELogin;
            if (orderToCompare == null) return 1;
            return ProviderName.CompareTo(orderToCompare.ProviderName);
        }
    }
}