import typing as t
from datetime import datetime
from foundry_sdk.db_mgmt import Writer, SQLDatabase, InsertionMode


class Company(Writer):
    TABLE = "companies"
    COLUMNS = ["name", "dataset_type", "description", "min_date", "max_date"]
    TYPES = [str, str, str, datetime, datetime]
    UNIQUE = ["name"]
    AUTO_ID = True

    def __init__(self, db: SQLDatabase, insertion_mode: InsertionMode):
        super().__init__(db, insertion_mode)

class Stores(Writer):
    TABLE = "stores"
    COLUMNS = ["companyID", "regionID", "name"]
    TYPES = [int, int, str]
    UNIQUE = ["companyID", "name"]
    AUTO_ID = True

    def __init__(self, db: SQLDatabase, insertion_mode: InsertionMode):
        super().__init__(db, insertion_mode)
    
class CategoryLevelDescriptions(Writer):
    TABLE = "category_level_descriptions"
    COLUMNS = ["level", "name", "companyID"]
    UNIQUE = ["level", "name", "companyID"]
    TYPES = [int, str, int]
    AUTO_ID = True 

class CategoryRelations(Writer):
    TABLE = "category_relations"
    COLUMNS = ["subID", "parentID"]
    TYPES = [int, int]
    UNIQUE = ["subID", "parentID"]
    AUTO_ID = False

class Categories(Writer):
    TABLE = "categories"
    COLUMNS = ["companyID", "name"]
    TYPES = [int, str]
    UNIQUE = ["companyID", "name"]
    AUTO_ID = True

class Products(Writer):
    TABLE = "products"
    COLUMNS = ["name", "companyID"]
    TYPES = [str, int]
    UNIQUE = ["name", "companyID"]
    AUTO_ID = True

class ProductCategories(Writer):
    TABLE = "product_categories"
    COLUMNS = ["productID", "categoryID"]
    TYPES = [int, int]
    UNIQUE = ["productID", "categoryID"]
    AUTO_ID = False

class SKUTable(Writer):
    TABLE = "sku_table"
    COLUMNS = ["productID", "storeID", ]
    TYPES = [int, int]
    UNIQUE = ["productID", "storeID"]
    AUTO_ID = True

class DataPoints(Writer):
    TABLE = "datapoints"
    COLUMNS = ["skuID", "dateID"]
    TYPES = [int, int]
    UNIQUE = ["skuID", "dateID"]
    AUTO_ID = True

class GENERIC_TIME_SKU_DATA(Writer):
    COLUMNS = ["datapointID", "value"]
    TYPES = [int, float]
    UNIQUE = ["datapointID"]
    AUTO_ID = False

    def __init__(self, db: SQLDatabase, insertion_mode: InsertionMode, table_name: str):
        self.TABLE = table_name
        super().__init__(db, insertion_mode) 
    
class StoreFeatureDescription(Writer):
    TABLE = "store_features_description"
    COLUMNS = ["name", "description", "companyID"]
    TYPES = [str, str, int]
    UNIQUE = ["name", "companyID"]
    AUTO_ID = True

class StoreFeatures(Writer):
    TABLE = "store_features"
    COLUMNS = ["storeID", "sfID", "value"]
    TYPES = [int, int, str]
    UNIQUE = ["storeID", "sfID"]
    AUTO_ID = False

class ProductFeatureDescription(Writer):
    TABLE = "product_features_description"
    COLUMNS = ["name", "description", "companyID"]
    TYPES = [str, str, int]
    UNIQUE = ["name", "companyID"]
    AUTO_ID = True

class ProductFeatures(Writer):
    TABLE = "product_features"
    COLUMNS = ["storeID", "sfID", "value"]
    TYPES = [int, int, str]
    UNIQUE = ["storeID", "sfID"]
    AUTO_ID = False

class TimeProductFeatureDescription(Writer):
    TABLE = "store_features_description"
    COLUMNS = ["name", "description", "companyID"]
    TYPES = [str, str, int]
    UNIQUE = ["name", "companyID"]
    AUTO_ID = True

class TimeProductFeatures(Writer):
    TABLE = "store_features"
    COLUMNS = ["productID", "tpfID", "value"]
    TYPES = [int, int, str]
    UNIQUE = ["productID", "dateID", "tpfID"]
    AUTO_ID = False

class TimeRegionFeatureDescription(Writer):
    TABLE = "time_region_features_description"
    COLUMNS = ["name", "description", "companyID"]
    TYPES = [str, str, int]
    UNIQUE = ["name", "companyID"]
    AUTO_ID = True

class TimeRegionFeatures(Writer):
    TABLE = "time_region_features"
    COLUMNS = ["regionID", "dateID", "trfID", "value"]
    TYPES = [int, int, int, str]
    UNIQUE = ["regionID", "dateID", "trfID"]
    AUTO_ID = False

class TimeStoreFeatureDescription(Writer):
    TABLE = "time_store_features_description"
    COLUMNS = ["name", "description", "companyID"]
    TYPES = [str, str, int]
    UNIQUE = ["name", "companyID"]
    AUTO_ID = True

class TimeStoreFeatures(Writer):
    TABLE = "time_store_features"
    COLUMNS = ["storeID", "dateID", "tsfID", "value"]
    TYPES = [int, int, int, str]
    UNIQUE = ["storeID", "dateID", "tsfID"]
    AUTO_ID = False

