import torch

from data.config import Config
from data.weibo.data_loader import WeiboDatasetLoader


class WeiboConfig(Config):
    name = 'weibo'
    DatasetLoader = WeiboDatasetLoader

    data_path = '../../../../../media/external_3TB/3TB/ghorbanpoor/weibo/'
    # data_path = '/home/faeze/PycharmProjects/fake_news_detection/data/weibo/'
    output_path = '../../../../../media/external_10TB/10TB/ghorbanpoor/'
    # output_path = ''

    rumor_image_path = data_path + 'rumor_images/'
    nonrumor_image_path = data_path + 'nonrumor_images/'

    train_text_path = data_path + 'weibo_train.csv'
    validation_text_path = data_path + 'weibo_train.csv'
    test_text_path = data_path + 'weibo_test.csv'

    batch_size = 100
    epochs = 100
    num_workers = 1
    head_lr = 0.0085
    image_encoder_lr = 1.0e-05
    text_encoder_lr = 0.00016
    weight_decay = 0.00015
    classification_lr = 0.00149

    hidden_size = 128
    projection_size = 64
    dropout = 0.5

    device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")

    image_model_name = '../../../../../media/external_10TB/10TB/ghorbanpoor/huggingface/vit-base-patch16-224'
    image_embedding = 768
    text_encoder_model = "../../../../../media/external_10TB/10TB/ghorbanpoor/huggingface/bert-base-chinese"
    # text_encoder_model = "/home/faeze/PycharmProjects/new_fake_news_detectioin/bert/bert-base-uncased"
    text_tokenizer = "../../../../../media/external_10TB/10TB/ghorbanpoor/huggingface/bert-base-chinese"
    # text_tokenizer = "/home/faeze/PycharmProjects/new_fake_news_detectioin/bert/bert-base-uncased"
    text_embedding = 768
    max_length = 200

    pretrained = True
    trainable = False
    temperature = 1.0

    labels = ['real', 'fake']

    wanted_accuracy = 0.85

    def optuna(self, trial):
        self.head_lr = trial.suggest_loguniform('head_lr', 1e-5, 1e-1)
        self.image_encoder_lr = trial.suggest_loguniform('image_encoder_lr', 1e-6, 1e-3)
        self.text_encoder_lr = trial.suggest_loguniform('text_encoder_lr', 1e-6, 1e-3)
        self.classification_lr = trial.suggest_loguniform('classification_lr', 1e-5, 1e-1)

        self.head_weight_decay = trial.suggest_loguniform('head_weight_decay', 1e-5, 1e-1)
        # self.classification_weight_decay = trial.suggest_loguniform('classification_weight_decay', 1e-5, 1e-1)

        self.projection_size = trial.suggest_categorical('projection_size', [256, 128, 64])
        # self.hidden_size = trial.suggest_categorical('hidden_size', [256, 128, 64, ])
        self.dropout = trial.suggest_categorical('drop_out', [0.1, 0.3, 0.5, ])

