#!/usr/bin/env python
# -*- encoding: utf-8 -*-
#
# Copyright (c) 2016 Stephen Bunn <ritashugisha>
# MIT License <https://opensource.org/licenses/MIT>

"""
tile
.. module:: models
    :platform: Linux, MacOSX, Win32
    :synopsis:
    :created: 2016-09-30T08:56:59-04:00
.. moduleauthor:: Stephen Bunn <ritashugisha> (ritashugisha@gmail.com)

"""

import string


class Tile(object):
    """ An class of tiles including letter and point values for all letters.

    """

    TILE_VALUES = {
        'a': 1,
        'b': 3,
        'c': 3,
        'd': 2,
        'e': 1,
        'f': 4,
        'g': 2,
        'h': 4,
        'i': 1,
        'j': 8,
        'k': 5,
        'l': 1,
        'm': 3,
        'n': 1,
        'o': 1,
        'p': 3,
        'q': 10,
        'r': 1,
        's': 1,
        't': 1,
        'u': 1,
        'v': 4,
        'w': 4,
        'x': 8,
        'y': 4,
        'z': 10,
        '': 0
    }

    def __init__(self, letter):
        if letter in self.TILE_VALUES:
            self._letter = letter
        else:
            raise ValueError((
                "invalid tile letter '{letter}'"
            ).format(letter=letter))

    def __repr__(self):
        return ((
            '<{self.__class__.__module__}.{self.__class__.__name__} '
            '"{self._letter}" value={self.value}>'
        ).format(self=self))

    def __eq__(self, other):
        return self._letter == other.letter

    @property
    def letter(self):
        return self._letter

    @property
    def value(self):
        return (
            self.TILE_VALUES[self._letter.lower()]
            if self._letter and self._letter in string.ascii_letters else
            0
        )


class BlankTile(Tile):

    def __init__(self, letter):
        self._letter = letter

    @property
    def value(self):
        return 0


class NullTile(Tile):

    def __init__(self):
        (self._letter, self._value) = (None, None)
