/*
 * Copyright (C) 2023 Uniontech Software Technology Co., Ltd.
 *
 * Author:     zhangsheng<zhangsheng@uniontech.com>
 *
 * Maintainer: zhangsheng<zhangsheng@uniontech.com>
 *
 * 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
 * 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/>.
 */

#ifndef BURNCHECKSTRATEGY_H
#define BURNCHECKSTRATEGY_H

#include <QObject>
#include <QFileInfo>

class BurnCheckStrategy : public QObject
{
    Q_OBJECT

public:
    explicit BurnCheckStrategy(const QString &path, QObject *parent = nullptr);
    bool check();
    QString lastError() const;
    QString lastInvalidName() const;

private:
    bool validFile(const QFileInfo &info);

protected:
    bool validCommonFileNameBytes(const QString &fileName);
    bool validComontFilePathBytes(const QString &filePath);
    bool validCommonFilePathDeepLength(const QString &filePath);

    virtual bool validFileNameCharacters(const QString &fileName);
    virtual bool validFilePathCharacters(const QString &filePath);
    virtual bool validFileNameBytes(const QString &fileName);
    virtual bool validFilePathBytes(const QString &filePath);
    virtual bool validFilePathDeepLength(const QString &filePath);

protected:
    QString invalidName;
    QString errorMsg;
    QString currentStagePath;
};

class ISO9660CheckStrategy final : public BurnCheckStrategy
{
    Q_OBJECT

public:
    explicit ISO9660CheckStrategy(const QString &path, QObject *parent = nullptr);

protected:
    bool validFileNameCharacters(const QString &fileName) override;
    bool validFilePathDeepLength(const QString &filePath) override;

};

class JolietCheckStrategy final : public BurnCheckStrategy
{
    Q_OBJECT

public:
    explicit JolietCheckStrategy(const QString &path, QObject *parent = nullptr);

protected:
    bool validFileNameCharacters(const QString &fileName) override;
    bool validFilePathCharacters(const QString &filePath) override;
};

class RockRidgeCheckStrategy final : public BurnCheckStrategy
{
    Q_OBJECT

public:
    explicit RockRidgeCheckStrategy(const QString &path, QObject *parent = nullptr);

protected:
    bool validFileNameBytes(const QString &fileName) override;
    bool validFilePathBytes(const QString &filePath) override;
    bool validFilePathDeepLength(const QString &filePath) override;
};

class UDFCheckStrategy final : public BurnCheckStrategy
{
    Q_OBJECT

public:
    explicit UDFCheckStrategy(const QString &path, QObject *parent = nullptr);

protected:
    bool validFileNameBytes(const QString &fileName) override;
    bool validFilePathBytes(const QString &filePath) override;
};

#endif   // BURNCHECKSTRATEGY_H
