// Created with MonoDevelop
//
//    QuickStep: Acquire, view and identify spectra 
//    Copyright (C) 2021 Torsten Schache, Hiperscan GmbH Dresden, Germany
//
//    This program is free software: you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation, either version 3 of the License, or
//    (at your option) any later version.
//
//    This program is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU General Public License for more details.
//
//    You should have received a copy of the GNU General Public License
//    along with this program.  If not, see <http://www.gnu.org/licenses/>.

using System;
using System.Globalization;
using System.Runtime.Serialization;

namespace Hiperscan.ApoIdentCommon
{
    [DataContract(Name = "DecodedBase64Address", Namespace = "http://schemas.datacontract.org/2004/07/Hiperscan.ApoIdentCommon.ApoIdentInterface")]
    public class DecodedBase64Address : System.Runtime.Serialization.IExtensibleDataObject
    {
        public DecodedBase64Address(string[] address_data)
        {
            this.CustomerNumber = address_data[0];
            this.Company = address_data[1];
            this.Street = address_data[2];
            this.Town = address_data[3];
            this.Creator = address_data[4];
            this.TimeStamp = DateTime.Parse(address_data[5], CultureInfo.InvariantCulture);
        }

        [DataMember] public string CustomerNumber { get; private set; }
        [DataMember] public string Company { get; private set; }
        [DataMember] public string Street { get; private set; }
        [DataMember] public string Town { get; private set; }
        [DataMember] public string Creator { get; private set; }
        [DataMember] public DateTime TimeStamp { get; private set; }

        public ExtensionDataObject extension_data = null;
        public ExtensionDataObject ExtensionData
        {
            get { return this.extension_data; }
            set { this.extension_data = value; }
        }

        public static implicit operator string[](DecodedBase64Address address)
        {
            return new string[] {address.CustomerNumber, address.Company, address.Street, address.Town,
                address.Creator, address.TimeStamp.ToString(CultureInfo.InvariantCulture)};
        }
    }
}
