<commit_before>﻿using System;
using System.Linq;
using Bit.Core.Models.Table;
using System.Collections.Generic;
using Bit.Core.Models.Business;
using Stripe;

namespace Bit.Core.Models.Api
{
    public class OrganizationResponseModel : ResponseModel
    {
        public OrganizationResponseModel(Organization organization, string obj = "organization")
            : base(obj)
        {
            if(organization == null)
            {
                throw new ArgumentNullException(nameof(organization));
            }

            Id = organization.Id.ToString();
            Name = organization.Name;
            BusinessName = organization.BusinessName;
            BillingEmail = organization.BillingEmail;
            Plan = organization.Plan;
            PlanType = organization.PlanType;
            Seats = organization.Seats;
        }

        public string Id { get; set; }
        public string Name { get; set; }
        public string BusinessName { get; set; }
        public string BillingEmail { get; set; }
        public string Plan { get; set; }
        public Enums.PlanType PlanType { get; set; }
        public short? Seats { get; set; }
    }

    public class OrganizationBillingResponseModel : OrganizationResponseModel
    {
        public OrganizationBillingResponseModel(Organization organization, OrganizationBilling billing)
            : base(organization, "organizationBilling")
        {
            PaymentSource = billing.PaymentSource != null ? new BillingSource(billing.PaymentSource) : null;
            Subscription = billing.Subscription != null ? new BillingSubscription(billing.Subscription) : null;
            Charges = billing.Charges.Select(c => new BillingCharge(c));
        }

        public BillingSource PaymentSource { get; set; }
        public BillingSubscription Subscription { get; set; }
        public IEnumerable<BillingCharge> Charges { get; set; }

        public class BillingSource
        {
            public BillingSource(Source source)
            {
                Type = source.Type;

                switch(source.Type)
                {
                    case SourceType.Card:
                        Description = $"{source.Card.Brand}, *{source.Card.Last4}, " +
                            $"{source.Card.ExpirationMonth}/{source.Card.ExpirationYear}";
                        CardBrand = source.Card.Brand;
                        break;
                    case SourceType.BankAccount:
                        Description = $"{source.BankAccount.BankName}, *{source.BankAccount.Last4}";
                        break;
                    // bitcoin/alipay?
                    default:
                        break;
                }
            }

            public SourceType Type { get; set; }
            public string CardBrand { get; set; }
            public string Description { get; set; }
        }

        public class BillingSubscription
        {
            public BillingSubscription(StripeSubscription sub)
            {
                Status = sub.Status;
                TrialStartDate = sub.TrialStart;
                TrialEndDate = sub.TrialEnd;
                NextBillDate = sub.CurrentPeriodEnd;
                CancelledDate = sub.CanceledAt;
                CancelAtNextBillDate = sub.CancelAtPeriodEnd;
                if(sub.Items?.Data != null)
                {<commit_msg>pad month with 0<commit_after>﻿using System;
using System.Linq;
using Bit.Core.Models.Table;
using System.Collections.Generic;
using Bit.Core.Models.Business;
using Stripe;

namespace Bit.Core.Models.Api
{
    public class OrganizationResponseModel : ResponseModel
    {
        public OrganizationResponseModel(Organization organization, string obj = "organization")
            : base(obj)
        {
            if(organization == null)
            {
                throw new ArgumentNullException(nameof(organization));
            }

            Id = organization.Id.ToString();
            Name = organization.Name;
            BusinessName = organization.BusinessName;
            BillingEmail = organization.BillingEmail;
            Plan = organization.Plan;
            PlanType = organization.PlanType;
            Seats = organization.Seats;
        }

        public string Id { get; set; }
        public string Name { get; set; }
        public string BusinessName { get; set; }
        public string BillingEmail { get; set; }
        public string Plan { get; set; }
        public Enums.PlanType PlanType { get; set; }
        public short? Seats { get; set; }
    }

    public class OrganizationBillingResponseModel : OrganizationResponseModel
    {
        public OrganizationBillingResponseModel(Organization organization, OrganizationBilling billing)
            : base(organization, "organizationBilling")
        {
            PaymentSource = billing.PaymentSource != null ? new BillingSource(billing.PaymentSource) : null;
            Subscription = billing.Subscription != null ? new BillingSubscription(billing.Subscription) : null;
            Charges = billing.Charges.Select(c => new BillingCharge(c));
        }

        public BillingSource PaymentSource { get; set; }
        public BillingSubscription Subscription { get; set; }
        public IEnumerable<BillingCharge> Charges { get; set; }

        public class BillingSource
        {
            public BillingSource(Source source)
            {
                Type = source.Type;

                switch(source.Type)
                {
                    case SourceType.Card:
                        Description = $"{source.Card.Brand}, *{source.Card.Last4}, " +
                            string.Format("{0}/{1}",
                                string.Concat(source.Card.ExpirationMonth.Length == 1 ?
                                    "0" : string.Empty, source.Card.ExpirationMonth),
                                source.Card.ExpirationYear);
                        CardBrand = source.Card.Brand;
                        break;
                    case SourceType.BankAccount:
                        Description = $"{source.BankAccount.BankName}, *{source.BankAccount.Last4}";
                        break;
                    // bitcoin/alipay?
                    default:
                        break;
                }
            }

            public SourceType Type { get; set; }
            public string CardBrand { get; set; }
            public string Description { get; set; }
        }

        public class BillingSubscription
        {
            public BillingSubscription(StripeSubscription sub)
            {
                Status = sub.Status;
                TrialStartDate = sub.TrialStart;
                TrialEndDate = sub.TrialEnd;
                NextBillDate = sub.CurrentPeriodEnd;
                CancelledDate = sub.CanceledAt;
                CancelAtNextBillDate = sub.CancelAtPeriodEnd;
                if(sub.Items?.Data != null)
                {
{'fraction_non_alphanumeric': 0.08142201834862385, 'fraction_numerical': 0.0012901376146788992, 'mean_word_length': 1.655881233346022, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3519360', 'n_tokens_mistral': 1732, 'n_tokens_neox': 1636, 'n_words': 375}