//
//  RootFeature.swift
//  Root
//

import Foundation
import Facts
import CatFactsKit
import ComposableArchitecture

@Reducer
public struct RootFeature {
    @ObservableState
    public struct State {
        var facts: FactsFeature.State = .init(baseURL: URL(string: "https://invalid.barf")!)
        public var baseURL: URL?

        public init() { }
    }

    public enum Action {
        case viewAppeared
        case facts(FactsFeature.Action)
    }

    public init() { }
    
    public var body: some ReducerOf<Self> {
        Reduce { state, action in
            switch action {
            case .viewAppeared:
                state.facts = .init(baseURL: URL(string: "https://meowfacts.herokuapp.com/")!)
                return .none
            case .facts:
                return .none
            }
        }
        Scope(state: \.facts, action: \.facts) {
            FactsFeature()
        }
    }
}
