# encoding: utf-8
#
# Copyright (C) 2020 willipink.eu
# Author Moritz Münch moritzmuench@mailbox.org
#
# 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/>.



from datetime import datetime, date

from django.db.models import BooleanField, CASCADE, CharField, DateField, ForeignKey, Model, PositiveIntegerField, PositiveSmallIntegerField, TextField


year_now        = int(datetime.now().year)



class User(Model):
    name            = CharField('Name', max_length=20, default='Anonym')

    color           = CharField('Farbe', max_length=20, default='purple')


    def __str__(self):
        return self.name



class Country(Model):
    name_iso        = CharField('Kürzel', max_length=2, primary_key=True)

    name            = CharField('Land', max_length=50)

    comment         = TextField('Kommentar', default='', blank=True)

    euro_member_since      = PositiveSmallIntegerField('Währungsmitglied seit', default=year_now)


    def __str__(self):
        return f"{self.name} {self.name_iso}  {self.comment}"



class Stamp(Model):
    name_short      = CharField('Prägung', max_length=10, primary_key=True)

    name            = CharField('Name', max_length=50)

    years           = TextField('Im Einsatz in den Jahren ("" entspricht allen Jahren)', default='', blank=True)

    comment         = TextField('Kommentar', default='', blank=True)

    country         = ForeignKey('Country', on_delete=CASCADE, null=True, blank=True)


    def __str__(self):
        return f"{self.name_short} - {self.name}"



class Coin(Model):
    value           = PositiveSmallIntegerField('Wert', default=100)

    year            = PositiveSmallIntegerField('Jahr', default=year_now)

    country         = ForeignKey('Country', on_delete=CASCADE)

    stamp           = ForeignKey('Stamp', on_delete=CASCADE, null=True, blank=True)

    name            = TextField('Name', default='', blank=True)

    found_by        = ForeignKey('User', on_delete=CASCADE, null=True, blank=True)

    found_on        = DateField('Eingetragen am', default=date.today)

    circulation     = PositiveIntegerField('Auflage', default=0)

    buy_only        = BooleanField('Kursmünze', default=False)

    checked         = BooleanField('Von Gigo geprüft und einsortiert', default=False)

    in_collector    = BooleanField('Im Eurocollector 2002', default=False)

    exists          = BooleanField('Existiert', default=True)

    fault_stamp     = BooleanField('Fehlprägung', default=False)

    comment         = TextField('Kommentar', default='', blank=True)


    def __str__(self):
        return f"{self.value} {self.stamp} aus {self.country.name} {self.year} {self.name}"
