/*
 * Copyright 2013 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * 	http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package io.github.carlomicieli.springbooks;

import io.github.carlomicieli.springbooks.config.ApplicationConfig;
import io.github.carlomicieli.springbooks.domain.Book;
import io.github.carlomicieli.springbooks.services.BookService;
import io.github.carlomicieli.springbooks.services.InitService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

import java.util.List;

public class MainClass {

    static Logger log = LoggerFactory.getLogger(MainClass.class);

    public static void main(String[] args) {
        AnnotationConfigApplicationContext ctx =
                new AnnotationConfigApplicationContext(ApplicationConfig.class);
//        ctx.getEnvironment().setActiveProfiles("default");
//        ctx.register(ApplicationConfig.class);
//        ctx.refresh();

        log.info("Running sample application...");
        InitService s = ctx.getBean("initService", InitService.class);

        log.info("Dropping books collection...");
        s.dropBooks();

        log.info("Init books collection...");
        s.initBooks();

        BookService s2 = ctx.getBean(BookService.class);
        List<Book> books = s2.findByCommentAuthor("Jane Doe");

        System.out.println(books.size());
    }
}
