// videostore.cpp
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

struct Video {
    std::string title;
    std::string director;
    std::string genre;
    int rating;
    double price;
};

std::vector<Video> videos;

void addVideo(const Video& video) {
    videos.push_back(video);
}

void printVideos() {
    for (const auto& video : videos) {
        std::cout << "Название: " << video.title << ", Режиссер: " << video.director << ", Жанр: " << video.genre << ", Рейтинг: " << video.rating << ", Цена: " << video.price << std::endl;
    }
}

std::vector<Video> searchByTitle(const std::string& title) {
    std::vector<Video> result;
    for (const auto& video : videos) {
        if (video.title == title) {
            result.push_back(video);
        }
    }
    return result;
}

std::vector<Video> searchByGenre(const std::string& genre) {
    std::vector<Video> result;
    for (const auto& video : videos) {
        if (video.genre == genre) {
            result.push_back(video);
        }
    }
    return result;
}

std::vector<Video> searchByDirector(const std::string& director) {
    std::vector<Video> result;
    for (const auto& video : videos) {
        if (video.director == director) {
            result.push_back(video);
        }
    }
    return result;
}

Video mostPopularInGenre(const std::string& genre) {
    Video popular = {"", "", "", 0, 0.0};
    for (const auto& video : videos) {
        if (video.genre == genre && video.rating > popular.rating) {
            popular = video;
        }
    }
    return popular;
}

int main() {
    addVideo({"Inception", "Christopher Nolan", "Sci-Fi", 9, 19.99});
    addVideo({"The Dark Knight", "Christopher Nolan", "Action", 9, 14.99});
    addVideo({"Interstellar", "Christopher Nolan", "Sci-Fi", 8, 17.99});

    std::cout << "Все видео:" << std::endl;
    printVideos();

    std::vector<Video> results = searchByTitle("Inception");
    std::cout << "Поиск по названию 'Inception':" << std::endl;
    for (const auto& video : results) {
        std::cout << "Найдено: " << video.title << std::endl;
    }

    results = searchByGenre("Sci-Fi");
    std::cout << "Поиск по жанру 'Sci-Fi':" << std::endl;
    for (const auto& video : results) {
        std::cout << "Найдено: " << video.title << std::endl;
    }

    results = searchByDirector("Christopher Nolan");
    std::cout << "Поиск по режиссеру 'Christopher Nolan':" << std::endl;
    for (const auto& video : results) {
        std::cout << "Найдено: " << video.title << std::endl;
    }

    Video popular = mostPopularInGenre("Sci-Fi");
    std::cout << "Самый популярный фильм в жанре 'Sci-Fi': " << popular.title << std::endl;

    return 0;
}

