package models

import (
	"strings"
	"time"
)

// Currency model
type Currency struct {
	Currency_id string  `json:"currency_id"`
	Curs_date   string  `json:"curs_date"`
	Num_code    int     `json:"num_code"`
	Char_code   string  `json:"char_code"`
	Nominal     int     `json:"nominal"`
	Value       float64 `json:"value"`
}

type CurrencyList struct {
	ValueList []Currency
}

func DateForQueryPrepare(s string) string {
	layout := "2006-01-02"
	queryLayout := "2006-01-02 15:04:05+00:00"
	TimestampDate, _ := time.Parse(layout, s)
	return TimestampDate.Format(queryLayout)
}

func DateArrayForQueryPrepare(s string) string {
	var result string

	layout := "2006-01-02"
	queryLayout := "'2006-01-02 15:04:05+00:00',"
	dates := strings.Split(s, ",")

	for _, date := range dates {
		var TimestampDate time.Time
		TimestampDate, _ = time.Parse(layout, date)
		result += TimestampDate.Format(queryLayout)
	}

	return result[:len(result)-1]
}

func (cl *CurrencyList) AddCurrency(c Currency) []Currency {
	cl.ValueList = append(cl.ValueList, c)
	return cl.ValueList
}
